import heapq
from typing import List


class HalveArray:
    # 将数组和减半的最少操作次数:  数组和 + 相反数小顶堆操作
    def halveArray(self, nums: List[int]) -> int:
        total = sum(nums)
        n = len(nums)
        for i in range(n):
            nums[i] = - nums[i]
        heapq.heapify(nums)
        dec = 0.0
        res = 0
        while dec < total / 2:
            opt = heapq.heappop(nums)
            dec += -opt / 2
            res += 1
            heapq.heappush(nums, opt / 2)
        return res
